<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/9/17 0017
 * Time: 上午 11:31
 */

namespace app\common\service;
use think\Request;

/**
 * 日志服务
 * 需要有日志表
 * Class Log
 * @package app\common\service
 */
class Log extends Service
{
    /**
     * @param string $key
     * @param string $content
     * @param int $type
     * @return array
     */
    public function log($key='',$content='',$type=1){
        $data['remarks']="[{$key}]:".$content;
        $data['position']=get_current_url();
        $data['ip']=Request::instance()->ip();
        $data['type']=$type;
        $data['createtime']=time();
        return db('log')->insert($data);
    }

    /**
     * @param string $key
     * @param string $content
     * @return array
     */

    public function debugLog($key='',$content=''){
        return $this->log($key,$content,2);
    }

    /**
     * @param string $key
     * @param string $content
     * @return array
     */
    public function errorLog($key='',$content=''){
        return $this->log($key,$content,3);
    }

    /**
     * @param string $key
     * @param string $content
     * @return array
     */
    public function infoLog($key='',$content=''){
        return $this->log($key,$content,1);
    }
}